<layout name="page"/>
<block name="content">
	<input type="hidden" name="popup_val" id="popup_val">
	<input type="hidden" name="popup_name" id="popup_name">
	{:widget('page_header/simple',array('name'=>$folder_name))}
	<div class="operate-panel">
		<a class="btn btn-return" onclick="go_return_url()">返回</a>
		<a class="btn btn-normal" onclick="import_data()">导入</a>
		<a class="btn btn-normal" onclick="export_data()" >导出</a>
		<i class="x1"></i>
		<a class="btn btn-normal" onclick="add()" >新增</a>
		<a class="btn btn-normal" onclick="save()">保存</a>
		<i class="split"></i>
		<a class="btn btn-del" onclick="del()">删除</a>
	</div>
	<div class="sub box">
		<div class="w28 m100 frame" style="max-height:450px;overflow-y: auto;">
			<div class="tree-menu">
				{:widget('html/tree_menu',array($tree_menu))}
			</div>
		</div>
		<div style="width:16px;"></div>
		<div class="x1 frame m100" style="height:450px;">
			<form method='post' id="form_data" >
				<input type="hidden" name="controller" id="controller" value="{$Think.APP_NAME}">
				<input type="hidden" name="row_type" id="row_type" value="{$row_type}">
				<input type="hidden" name="id" id="id" >
				<input type="hidden" id="opmode" name="opmode" value="edit">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<div class="box col-12">
					<label class="input-label" for="name">名称*：</label>
					<input class="input" type="text" id="name" name="name" check="required" info="请输入名称">
				</div>
				<div class="box col-12">
					<label class="input-label" for="layout">控件布局：</label>
					<select name="layout" id="layout" check="required" info="请选择控件布局" class="select w16">
						<option value="">请选择 </option>
						<option value="1">一行两列</option>
						<option value="2">一行一列</option>
						<option value="3">占一整行</option>
						<option value="4">由控件控制</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="box">
					<label class="input-label" for="type">控件类型*：</label>
					<select name="type" id="type" check="required" info="请选择控件类型" class="select w16">
						<option value="">请选择</option>
						<option value="popup">弹窗选择</option>
						<option value="add_file">文件上传</option>
						<option value="text">单行文本</option>
						<option value="date">日期 </option>
						<option value="datetime">日期+时间 </option>
						<option value="select">列表</option>
						<option value="link_select">联动列表</option>
						<option value="radio">单选</option>
						<option value="checkbox">多选 </option>
						<option value="textarea">多行文本 </option>
						<option value="editor">编辑器</option>
						<option value="simple">简易编辑器</option>
						<option value="help">帮助 </option>
						<option value="hr">分隔符</option>
						<option value="title">标题</option>
					</select>
					<i class="icon"></i>
				</div>
				<div class="box">
					<label class="input-label" for="data">控件数据：</label>
					<input  class="input" type="text" val="data" name="data" >
				</div>
				<div class="box">
					<label class="input-label" for="config">设置：</label>
					<input  class="input" type="text" id="config" name="config" >
				</div>
				<div class="box">
					<label class="input-label" for="sort">排序：</label>
					<input class="input" type="text" id="sort" name="sort" >
				</div>
				<div class="box">
					<label class="input-label" for="validate">验证：</label>
					<div class="input-block col-12 x-select">
						<select name="validate" id="validate" class="input col-12">
							<option value="">请选择 <option value="required">必选 <option value="email">邮件 <option value="number">数字
						</select>
					</div>
				</div>
				<div class="box">
					<label class="input-label" for="msg">错误提示：</label>
					<input  class="input" type="text" id="msg" name="msg" >
				</div>
			</form>
		</div>
	</div>
	{:widget('page_header/sub',array('name'=>"自定义字段显示预览",'search'=>'N'))}
	<form method='post' class="row frame">
		<foreach name="field_list" val="vo">
			{:widget('user_defined_field/edit',array($vo))}
		</foreach>
	</form>
</block>
<block name="js">
	<script>
		layui.use(['global', 'uploader', 'udf_field'], function() {
			var $ = layui.jquery;
			set_return_url();
			var fn = {
				import_data : function() {
					window.open("{:url('udf_field/import_data',array('row_type'=>$row_type,'controller'=>$controller))}", '_self');
				},
				export_data : function() {
					window.open("{:url('udf_field/export_data',array('row_type'=>$row_type))}", "_blank");
				},
				add : function() {
					winopen("{:url('udf_field/add',array('controller'=>$controller,'row_type'=>$row_type))}", 560, 470);
				},
				save : function() {
					send_form('form_data', "__SELF__", '__SELF__', function(ret) {
						if (ret.status) {
							layer.msg(ret.info);
							location.reload(true);
						} else {
							layer.msg(ret.info);
							return false;
						}
					});
				},
				del : function() {
					if ($(".sub .tree-menu a.active").length == 0) {
						layer.msg('请选择要删除的数据');
						return false;
					}
					//信息框-例2
					layer.msg('确定要删除吗?', {
						time : 0,
						btn : ['确定', '取消'],
						yes : function(index) {
							$("#opmode").val("del");
							send_form("form_data", "__SELF__", "__SELF__", function(ret) {
								if (ret.status == 1) {
									parent.layer.msg(ret.info);
									parent.layer.close(index);
									parent.location.reload(true);
								} else {
									parent.layer.msg(ret.info);
									return false;
								}
							});
						},
						no : function(index) {
							layer.close(index);
						}
					});
				}
			};
			win_exp(fn);

			$(".sub .tree-menu a").click(function() {
				$(".sub .tree-menu a.active").removeClass("active");
				$this = $(this);
				$this.addClass("active");
				send_ajax("{:url('udf_field/read')}", "id=" + $this.attr("node"), function(data) {
					show_data(data);
				});
				return false;
			});

			function show_data(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
			};
		});
	</script>
</block>